<?php
/**
 * @author qingyu8@staff.weibo.com
 * @date 2018/04/19
 */
use yii\bootstrap\Html;
use yii\widgets\LinkPager;

/* @var $this yii\web\View */
$this->registerCss('#sortable tr { line-height: 14px; }');
$saveUrl = \yii\helpers\Url::to(['savebookeritem']);
$this->registerJs('
$(".booker-item-save").click(function () {
            var self = $(this);
            var id = self.parent().parent().data("id"), name_cn = self.parent().parent().find("input[name=name_cn]").val();
            self.attr("disabled", "disabled");
            $.post("'.$saveUrl.'", "id=" + id + "&name_cn=" + name_cn, function (res) {
                console.log(res);
                self.removeAttr("disabled");
            }, "json");
        });
');
?><?php if ($type == 'boat') { ?>
	<table class="table table-hover table-responsive">
		<thead>
		<tr>
			<th>id</th>
			<th>名称</th>
			<th>英文名称</th>
			<th>国家</th>
			<th>国家中文</th>
			<th>logo</th>
			<th>主图</th>
			<th>源地址</th>
			<th>船舱总数</th>

			<th>地点</th>
			<th>描述</th>
			<th>描述中文</th>
			<th>取消政策</th>
			<th>取消政策中文</th>
			<th>建造年份</th>
			<th>宽度</th>
			<th>长度</th>
			<th>材料</th>
			<th>材料中文</th>
			<th>语言</th>
			<th>语言cn</th>
			<th>船上支付</th>
			<th>Nitrox Membrane</th>
			<th>Nitrox</th>
			<th>Wifi</th>
			<th>潜水设备</th>
			<th>技术潜水</th>
			<th>船舱图</th>

			<th>上次同步时间</th>
			<th>操作</th>
		</tr>
		</thead>
		<tbody id="sortable">
        <?php foreach ($data as $k => $v) { ?>
			<tr item-id="<?=$v['id']?>">
				<td><?=$v['id']?></td>
				<td><?=$v['name_cn']?></td>
				<td><?=$v['name_en']?></td>
				<td><?=$v['countries']?></td>
				<td><?=$v['countries_cn']?></td>
				<td><?='<img style="width:50px;max-height:50px;" src="' . $v['logo'] . '">'?></td>
				<td><img style="width: 50px;height: 50px;" src="<?=$v['main_image']?>"></td>
				<td><?=Html::a($v['booker_url'], $v['booker_url'],['target'=>'_blank'])?></td>
				<td><?=$v['cabin_total']?></td>

				<td><?=$v['location']?></td>
				<td><?=substr($v['description'],0,100)?> ...</td>
				<td><?=substr($v['desc_cn'],0,100)?> ...</td>
				<td><?=$v['policy']?></td>
				<td><?=$v['policy_cn']?></td>
				<td><?=$v['year_built']?></td>
				<td><?=$v['width']?></td>
				<td><?=$v['length']?></td>
				<td><?=$v['material']?></td>
				<td><?=$v['material_cn']?></td>
				<td><?=$v['languages']?></td>
				<td><?=$v['languages_cn']?></td>
				<td><?=$v['onboard_pay_method']?></td>
				<td><?=$v['nitrox_membrane']?></td>
				<td><?=$v['nitrox']?></td>
				<td><?=$v['wifi']?></td>
				<td><?=$v['diving_equipment']?></td>
				<td><?=$v['tech_diving_friendly']?></td>
				<td><img style="width: 50px;height: 50px;" src="<?=$v['cabin_pic']?>"></td>

				<td><?=$v['booker_last_update']?></td>
				<td class="action-btn-td"><?=Html::a('<i class="fa fa-pencil-square-o"></i>', [
                        'edit',
                        'id' => $v['id'],
                        'type' => $type
                    ], [
                        'class' => 'btn btn-sm btn-default modify-btn',
                        'aria-label' => '修改',
                    ]) . Html::a('<span class="fa fa-trash"></span>', [
                        'delete',
                        'id' => $v['id']
                    ], [
                        'aria-label' => Yii::t('yii', 'Delete'),
                        'data-confirm' => Yii::t('yii', 'Are you sure you want to delete this item?'),
                        'data-method' => 'post',
                        'data-pjax' => '0',
                        'class' => 'btn btn-sm btn-default',
                    ]);?></td>
			</tr>
        <?php } ?>
		</tbody>
	</table>
<?php } elseif ($type == 'trip') { ?>
	<table class="table table-hover">
		<thead>
		<tr>
			<th>id</th>
			<th>船id</th>
			<th>航线id</th>
			<th>名称</th>
			<th>英文名称</th>
			<th>开始日期</th>
			<th>结束日期</th>
			<th>描述</th>
			<th>取消政策</th>
			<th>取消政策中文</th>
			<th>出发地</th>
			<th>到达地</th>
			<th>空床位数</th>
			<th>上次同步时间</th>
			<th>操作</th>
		</tr>
		</thead>
		<tbody id="sortable">
        <?php foreach ($data as $k => $v) { ?>
			<tr item-id="<?=$v['id']?>">
				<td><?=$v['id']?></td>
				<td><?=Html::a($v['boat_id'], \yii\helpers\Url::to([
                        'source',
                        'id' => $v['boat_id']
                    ]), ['target' => '_blank'])?></td>
				<td><?=$v['tour_id']?></td>
				<td><?=$v['name_cn']?></td>
				<td><?=$v['name_en']?></td>
				<td><?=$v['start_time']?></td>
				<td><?=$v['end_time']?></td>

				<td><?=$v['description']?></td>
				<td><?=$v['policy']?></td>
				<td><?=$v['policy_cn']?></td>
				<td><?=$v['departure_location']?></td>
				<td><?=$v['arrival_location']?></td>
				<td><?=$v['free_spaces']?></td>

				<td><?=$v['update_time']?></td>
				<td class="action-btn-td"><?=Html::a('<i class="fa fa-pencil-square-o"></i>', [
                        'edit',
                        'id' => $v['id'],
                        'type' => $type
                    ], [
                        'class' => 'btn btn-sm btn-default modify-btn',
                        'aria-label' => '修改',
                    ]) . Html::a('<span class="fa fa-trash"></span>', [
                        'delete',
                        'id' => $v['id']
                    ], [
                        'aria-label' => Yii::t('yii', 'Delete'),
                        'data-confirm' => Yii::t('yii', 'Are you sure you want to delete this item?'),
                        'data-method' => 'post',
                        'data-pjax' => '0',
                        'class' => 'btn btn-sm btn-default',
                    ]);?></td>
			</tr>
        <?php } ?>
		</tbody>
	</table>
<?php } elseif ($type == 'tour') { ?>
	<table class="table table-hover">
		<thead>
		<tr>
			<th>id</th>
			<th>源</th>
			<th>名称</th>
			<th>英文名称</th>
			<th>描述</th>
			<th>描述中文</th>
			<th>货币</th>
			<th>要求最少潜次</th>
			<th>认证</th>
			<th>包含</th>
			<th>中文包含</th>
			<th>不包含</th>
			<th>中文不包含</th>
			<th>Check In</th>
			<th>Check Out</th>
			<th>出发地</th>
			<th>到达地</th>
			<th>出发地中文</th>
			<th>到达地中文</th>
			<th>出发港口</th>
			<th>到达港口</th>
			<th>几天</th>
			<th>几夜</th>
			<th>潜水次数</th>
			<th>上次同步时间</th>
			<th>操作</th>
		</tr>
		</thead>
		<tbody id="sortable">
        <?php foreach ($data as $k => $v) { ?>
			<tr item-id="<?=$v['id']?>">
				<td><?=$v['id']?></td>
				<td><?=Html::a($v['boatName'], \yii\helpers\Url::to([
                        'source',
                        'tourId' => $v['id']
                    ]), ['target' => '_blank'])?></td>
				<td><?=$v['name_cn']?></td>
				<td><?=$v['name_en']?></td>
				<td><?=substr($v['desc_en'],0,100). ' ...'?></td>
				<td><?=substr($v['desc_cn'], 0, 100) . ' ...'?></td>
				<td><?=$v['currency_symbol']?></td>
				<td><?=$v['experience']?></td>
				<td><?=$v['sertification']?></td>
				<td><?=substr($v['included'], 0, 100)?></td>
				<td><?=substr($v['included_cn'], 0, 100)?></td>
				<td><?=substr($v['notincluded'], 0, 100)?></td>
				<td><?=substr($v['notincluded_cn'], 0, 100)?></td>
				<td><?=$v['check_in']?></td>
				<td><?=$v['check_out']?></td>
				<td><?=$v['departure_location']?></td>
				<td><?=$v['arrival_location']?></td>
				<td><?=$v['departure_cn']?></td>
				<td><?=$v['arrival_cn']?></td>
				<td><?=$v['departure_port']?></td>
				<td><?=$v['arrival_port']?></td>
				<td><?=$v['duration']?></td>
				<td><?=$v['nights']?></td>
				<td><?=$v['dives']?></td>

				<td><?=$v['update_time']?></td>
				<td class="action-btn-td"><?=Html::a('<i class="fa fa-pencil-square-o"></i>', [
                        'edit',
                        'id' => $v['id'],
                        'type' => $type
                    ], [
                        'class' => 'btn btn-sm btn-default modify-btn',
                        'aria-label' => '修改',
                    ]) . Html::a('<span class="fa fa-trash"></span>', [
                        'delete',
                        'id' => $v['id']
                    ], [
                        'aria-label' => Yii::t('yii', 'Delete'),
                        'data-confirm' => Yii::t('yii', 'Are you sure you want to delete this item?'),
                        'data-method' => 'post',
                        'data-pjax' => '0',
                        'class' => 'btn btn-sm btn-default',
                    ]);?></td>
			</tr>
        <?php } ?>
		</tbody>
	</table>
<?php } elseif ($type == 'cabin') { ?>
	<table class="table table-hover">
		<thead>
		<tr>
			<th>id</th>
			<th>船id</th>
			<th>主图</th>
			<th>名称</th>
			<th>英文名称</th>
			<th>描述</th>
			<th>英文描述</th>
			<th>甲板</th>
			<th>甲板中文</th>
			<th>床型</th>
			<th>床型中文</th>
			<th>容纳人数</th>
			<th>浴室</th>
			<th>空调</th>
			<th>数量</th>
			<th>操作</th>
		</tr>
		</thead>
		<tbody id="sortable">
        <?php foreach ($data as $k => $v) { ?>
			<tr item-id="<?=$v['id']?>">
				<td><?=$v['id']?></td>
				<td><?=Html::a($v['boat_id'], \yii\helpers\Url::to([
                        'source',
                        'id' => $v['boat_id']
                    ]), ['target' => '_blank'])?></td>
				<td><img style="width: 50px;height: 50px;" src="<?=$v['img']?>"></td>
				<td><?=$v['name_cn']?></td>
				<td><?=$v['name_en']?></td>
				<td><?=$v['desc_cn']?></td>
				<td><?=$v['desc']?></td>
				<td><?=$v['deck']?></td>
				<td><?=$v['deck_cn']?></td>
				<td><?=$v['bedding']?></td>
				<td><?=$v['bedding_cn']?></td>
				<td><?=$v['occupancy']?></td>
				<td><?=$v['bathroom']?></td>
				<td><?=$v['aircon']?></td>
				<td><?=$v['cabin_number']?></td>
				<td class="action-btn-td"><?=Html::a('<i class="fa fa-pencil-square-o"></i>', [
                        'edit',
                        'id' => $v['id'],
                        'type' => $type
                    ], [
                        'class' => 'btn btn-sm btn-default modify-btn',
                        'aria-label' => '修改',
                    ]) . Html::a('<span class="fa fa-trash"></span>', [
                        'delete',
                        'id' => $v['id']
                    ], [
                        'aria-label' => Yii::t('yii', 'Delete'),
                        'data-confirm' => Yii::t('yii', 'Are you sure you want to delete this item?'),
                        'data-method' => 'post',
                        'data-pjax' => '0',
                        'class' => 'btn btn-sm btn-default',
                    ]);?></td>
			</tr>
        <?php } ?>
		</tbody>
	</table>
<?php } elseif ($type == 'occupancy') { ?>
	<table class="table table-hover">
		<thead>
		<tr>
			<th>id</th>
			<th>船舱id</th>
			<th>名称</th>
			<th>英文名称</th>
			<th>描述</th>
			<th>英文描述</th>
			<th>价格</th>
			<th>之前价格</th>
			<th>容纳人数</th>
			<th>当前人数</th>
			<th>操作</th>
		</tr>
		</thead>
		<tbody id="sortable">
        <?php foreach ($data as $k => $v) { ?>
			<tr item-id="<?=$v['id']?>">
				<td><?=$v['id']?></td>
				<td><?=Html::a($v['cabin_id'], \yii\helpers\Url::to([
                        'source',
                        'cabinId' => $v['cabin_id']
                    ]), ['target' => '_blank'])?></td>
				<td><?=$v['name_cn']?></td>
				<td><?=$v['name_en']?></td>
				<td><?=$v['desc_cn']?></td>
				<td><?=$v['desc_en']?></td>
				<td><?=$v['price']?></td>
				<td><?=$v['price_old']?></td>
				<td><?=$v['persons_max']?></td>
				<td><?=$v['persons_current']?></td>
				<td class="action-btn-td"><?=Html::a('<i class="fa fa-pencil-square-o"></i>', [
                        'edit',
                        'id' => $v['id'],
                        'type' => $type
                    ], [
                        'class' => 'btn btn-sm btn-default modify-btn',
                        'aria-label' => '修改',
                    ]) . Html::a('<span class="fa fa-trash"></span>', [
                        'delete',
                        'id' => $v['id']
                    ], [
                        'aria-label' => Yii::t('yii', 'Delete'),
                        'data-confirm' => Yii::t('yii', 'Are you sure you want to delete this item?'),
                        'data-method' => 'post',
                        'data-pjax' => '0',
                        'class' => 'btn btn-sm btn-default',
                    ]);?></td>
			</tr>
        <?php } ?>
		</tbody>
	</table>
<?php } elseif ($type == 'bookerItem') { ?>
	<table class="table table-hover">
		<thead>
		<tr>
			<th>id</th>
			<th>中文名称</th>
			<th>英文名称</th>
			<th>所属类型</th>
			<th>操作</th>
		</tr>
		</thead>
		<tbody id="sortable">
        <?php foreach ($data as $k => $v) { ?>
			<tr data-id="<?=$v['id']?>">
				<td><?=$v['id']?></td>
				<td><input type="text" name="name_cn" value="<?=$v['name_cn']?>"></td>
				<td><?=$v['name_en']?></td>
				<td><?=$v['type_en']?></td>
				<td class="action-btn-td">
					<button type="button" class="btn btn-default booker-item-save">保存</button>
				</td>
			</tr>
        <?php } ?>
		</tbody>
	</table>
<?php }?>
<script>

</script>
<?php
echo LinkPager::widget([
    'pagination' => $pages,
]) ?>
<span>共 <?=$total?> 条</span>
